<template>
  <div class="container">
    <div class="list-c">
      <div
        class="item"
        v-for="(item, index) in itemList"
        :key="index"
      >
        <div class="i-l">
          <span class="address">{{item.address}}{{item.detailed}}</span>
          <div class="user-info">
            <span class="s-l">{{item.addressee}}</span>
            <!-- <span class="s-m">{{item.gender}}</span> -->
            <span class="s-r">{{item.phone}}</span>
          </div>
        </div>
        <div>
          <i
            class="icon mt-edit-o"
            @click="updataAddress(index)"
          ></i></div>
          <!-- <img
            src="../../../static/images/dell.png"
            alt=""
            style="width:32rpx;height:32rpx;display:inline-block"
            @click="deleteAddress(item.id)"
          > -->
      </div>
    </div>
    <div
      class="add-btn"
      @click="addClick()"
    >
      <i class="icon mt-add-o"></i>
      <span>新增收货地址</span>
    </div>
  </div>
</template>

<script>
import {addressList} from './data'
import {request} from '@/wxRequest/requestApi'
export default {
	data() {
		return {
			itemList: [],
		}
	},
	onLoad() {
		this.getAddressListy()
	},
	methods: {
		//获取地址列表
		getAddressListy() {
			var that = this
			let getParams = {
				url: '/miniprogramOrder/userAddressList',
				data: {
					userId: wx.getStorageSync('userId'),
				},
				method: 'POST',
			}
			request(getParams).then(re => {
				that.itemList = re.data
			})
		},
		addClick() {
			wx.navigateTo({
				url: '/pages/addAddress/main',
			})
		},
		// //删除地址
		// deleteAddress(id) {
		// 	var that = this
		// 	let getParams = {
		// 		url: '/updateIsActived',
		// 		data: {
		// 			id: id,
		// 		},
		// 		method: 'POST',
		// 	}
		// 	request(getParams).then(re => {
		// 		wx.showToast({
		// 			title: '删除成功',
		// 			icon: 'success',
		// 			duration: 2000,
		// 			success() {
		// 				that.getAddressListy()
		// 			},
		// 		})
		// 	})
		// },
		//修改地址
		updataAddress(index) {
			let address = this.itemList[index]
			let detailAdress = address.detailed
			let dizhi = address.address
			let name = address.addressee
			let phone = address.phone
			let id = address.id
			wx.navigateTo({
				url:
					'/pages/updataAddress/main?detailAdress=' +
					detailAdress +
					'&dizhi=' +
					dizhi +
					'&name=' +
					name +
					'&phone=' +
					phone +
					'&id=' +
					id,
			})
		},
	},
	mounted() {},
}
</script>

<style lang="scss" scoped>
.container {
	.list-c {
		display: flex;
		flex-direction: column;
		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: white;
			padding: 30rpx;
			border-top: 2rpx solid $spLine-color;
			.i-l {
				display: flex;
				flex-direction: column;
				.address {
					font-size: 25rpx;
					color: $textBlack-color;
				}
				.user-info {
					display: flex;
					margin-top: 10rpx;
					.s-l {
						font-size: 25rpx;
						color: $textDarkGray-color;
					}
					.s-m {
						font-size: 25rpx;
						color: $textDarkGray-color;
						margin-left: 20rpx;
					}
					.s-r {
						font-size: 25rpx;
						color: $textDarkGray-color;
						margin-left: 60rpx;
					}
				}
			}
			i {
				font-size: 25rpx;
				color: $textDarkGray-color;
			}
		}
	}
	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 88rpx;
		background-color: white;
		border-top: 2rpx solid $spLine-color;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		i {
			font-size: 36rpx;
			color: $theme-color;
		}
		span {
			font-size: 28rpx;
			color: $textBlack-color;
			margin-left: 10rpx;
		}
	}
}
</style>
